<template>
  <div class="class-manual-container">
    <div class="flex alignCenter justifyBetween">
      <el-tabs v-model="activeName" class="class-tabs">
        <el-tab-pane label="B1 课程安排表" name="1"></el-tab-pane>
        <el-tab-pane label="B7 授课计划" name="2"></el-tab-pane>
        <el-tab-pane label="B7 教学分析及执行后记" name="3"></el-tab-pane>
        <el-tab-pane label="B8 教案" name="4"></el-tab-pane>
        <el-tab-pane label="B8 教案附表" name="5"></el-tab-pane>
        <el-tab-pane label="B9 教学日志" name="6"></el-tab-pane>
      </el-tabs>
      <div class="flex alignCenter" v-if="counter.isAdmin">
        <!-- <el-button type="primary" plain @click="proxy.$refs.fileClick.click()">模板上传</el-button> -->
        <el-button type="primary" plain @click="counter.downLoadTemplate('archives','档案导入模板')">模板下载</el-button>
        <el-button type="primary" @click="proxy.$refs.inputFile.click()">导入数据</el-button>
      </div>
    </div>

    <archivesCourseSchedule v-if="activeName==1" :archivesId="props.archivesId"></archivesCourseSchedule>

    <archivesTeachingPlan v-else-if="activeName==2" :archivesId="props.archivesId"></archivesTeachingPlan>

    <archivesInstructionalObjective v-else-if="activeName==3" :archivesId="props.archivesId"></archivesInstructionalObjective>

    <archivesLessonPlan v-else-if="activeName==4" :archivesId="props.archivesId"></archivesLessonPlan>

    <teachingPlanAppendix v-else-if="activeName==5" :archivesId="props.archivesId"></teachingPlanAppendix>

    <archivesTeachingLog v-else :archivesId="props.archivesId"></archivesTeachingLog>

    <!-- 导入数据 -->
    <input type="file" @change="handleFileUpload" v-show="false" ref="inputFile" />

    <!-- 模板上传 -->
    <input type="file" @change="handleFileImport" v-show="false" ref="fileClick" />
  </div>
</template>

<script setup lang="ts">
import archivesTeachingLog from "@/views/courseManage/components/archivesTeachingLog.vue";
import archivesCourseSchedule from "@/views/courseManage/components/archivesCourseSchedule.vue";
import archivesTeachingPlan from "@/views/courseManage/components/archivesTeachingPlan.vue";
import archivesInstructionalObjective from "@/views/courseManage/components/archivesInstructionalObjective.vue";
import archivesLessonPlan from "@/views/courseManage/components/archivesLessonPlan.vue";
import teachingPlanAppendix from "@/views/courseManage/components/teachingPlanAppendix.vue";
let props = defineProps(["archivesId"]);
const { proxy } = getCurrentInstance();
import { useRoute } from "vue-router";
const route = useRoute();
import useCounterStore from "@/store/counter";
const counter = useCounterStore();

let activeName = ref("1");

async function handleFileImport(event) {
  const files = event.target.files;
  counter.importTemplate(files, "archives");
}

async function handleFileUpload(event) {
  const files = event.target.files;
  let file = files[0];
  let resp = await proxy.$utils.fileToJson(file);
  let list = [];
  for (let index = 0; index < resp.length; index++) {
    const element = resp[index];
    if (index) {
      console.log(index, element[0], props.archivesId);
      if (element[0] != props.archivesId)
        return proxy.$utils.showToast(`第${index + 1}行档案 ID不匹配`, 0);
      list.push({
        archivesId: element[0],
        classIndex: element[1], //课次
        timeRange: element[2], //时间段
        classHour: element[3], //课时
        curriculum: element[4], //课程名称
        theoreticalClassHours: element[5], //理论课时
        practicalTrainingHours: element[6], //实训课时
        instructionalObjective: element[7], //教学目的
        trainingContent: element[8], //实训内容
        trainingEquipment: element[9], //实训设备
        teachingFocus: element[10], //教学重点
        teachingDifficulties: element[11], //教学难点
        teachingAids: element[12], //教学辅助
        teachingPostscript: element[13], //教学后记
        teachingNewsNotes: element[14], //教学动态记事
      });
    }
  }
  await proxy.$apis.scheduleRelevant({
    type: "archives-curriculum-import",
    data: list,
  });
  proxy.$utils.showToast("导入成功");
  setTimeout(() => {
    window.location.reload();
  }, 1200);
}
</script>


<style lang="scss">
.class-tabs {
  width: 100%;
  .el-tabs__nav-wrap::after {
    background-color: transparent !important;
  }
}
</style>
<style lang="scss" scoped>
.class-manual-container {
}
</style>

